﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using UniMana.Utils.Controls;
using UniMana.Utils.Configs;
using UniMana.Data;


namespace UniMana.Data
{
    public class Training_TrainingProgram_DetailInfo
    {
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();

        public Training_TrainingProgram_DetailInfo(int nProgramKey, int nSubjectKey)
        {
             var Iquery = m_data.m_DCSave.Training_TrainingProgram_Details.Where(p => p.Training_TrainingProgramKey == nProgramKey
                                                                                   && p.Training_SubjectKey ==nSubjectKey);
             m_bds.DataSource = Iquery;
             var Row = Iquery.FirstOrDefault();
             if (Row == null)
             {
                 Training_TrainingProgram_Detail detail = new Training_TrainingProgram_Detail();
                 detail.Training_TrainingProgramKey = nProgramKey;
                 detail.Training_SubjectKey = nSubjectKey;

                 Row = detail;
                 m_bds.Add(Row);
                 m_bds.MoveLast();
                
             }
        }

        public Training_TrainingProgram_Detail Properties
        {
            get { return m_bds.Current as Training_TrainingProgram_Detail; }

        }

        public void Delete()
        {
            m_bds.DeleteCurrent();
        }

        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
    }
}
